package com.yy.permissions_general.common.config.convert;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.yy.permissions_general.common.constant.SystemConstant;

import java.io.IOException;

/**
 * @Description: TODO 自定义的序列化类
 * @Author: YangYI
 * @Date: 2021/8/3
 **/
public class CustomLongConverter extends StdSerializer<Long> {


    public CustomLongConverter() {
        super(Long.class);
    }

    @Override
    public void serialize(Long value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        // 超过12个数字用String格式返回，由于js的number只能表示15个数字
        if (value.toString().length() > SystemConstant.JS_NUMBER_MAX_LENGTH) {
            jsonGenerator.writeString(value.toString());
        } else {
            jsonGenerator.writeNumber(value);
        }
    }
}
